package com.heima.wemedia.feign;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.feign.Wemedia.IWemediaClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.service.WmChannelService;
import com.heima.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 朱安东
 * @version 1.0
 * @project leadnews-project
 * @date 2024/1/26 16:55:30
 */
@RestController
public class WemediaClient implements IWemediaClient {

    @Autowired
    private WmUserService wmUserService;
    @Autowired
    private WmChannelService wmChannelService;


    /**
     * 获取用户名
     *
     * @param name 名字
     * @return {@link WmUser}
     */
    @Override
    @GetMapping("/wemedia/api/v1/user/findByName")
    public WmUser getUsername(@RequestParam("name") String name) {
        return wmUserService.getOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName, name));
    }

    @Override
    @PostMapping("/wemedia/api/v1/wm_user/save")
    public void createMediaAccount(WmUser wmUser) {
        wmUserService.save(wmUser);
    }
    /**
     * 查询所有可用频道
     *
     * @return
     */
    @GetMapping("/wemedia/api/v1/channel/channels")
    public ResponseResult channels(){
        return wmChannelService.findAll();
    }
}
